<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<%--部门编辑 --%>
		<base href="<%=basePath%>">
		<title>${title}</title>
		<meta http-equiv="pragma" content="no-cache"/>
		<meta http-equiv="cache-control" content="no-cache"/>
		<meta http-equiv="expires" content="0"/>    
		<link rel="stylesheet" type="text/css" href="<c:url value='/resource/css/common.css'/>"/>
		<link rel="stylesheet" type="text/css" href="<c:url value='/resource/css/jquery.autocomplete.css'/>"/>
		<script type="text/javascript" src="<c:url value='/resource/js/jquery-1.7.2.min.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/resource/js/jquery.form.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/resource/artdialog/artdialog.js?skin=${sys_theme}'/>"></script>
		<script type="text/javascript" src="<c:url value='/resource/artdialog/iframetools.js'/>"></script>
		<script type="text/javascript" src="<c:url value='/resource/js/jquery.autocomplete.js'/>"></script>		
		<script type="text/javascript" src="<c:url value='/resource/js/common.js'/>"></script>
		<style type="text/css">
			body{
				margin: 0;
				padding: 0;
			}
			.td_tit{
				width:100px;
				text-align: right;
			}
		</style>
<script type="text/javascript">
	function tipclose(content,alias,deptId,name,pageIndex){
		art.dialog.tips(content, 1.5);
		window.setTimeout(function(){
			window.parent.frames["ifrm_data"].frames["ifrm_deptlist"]._goto(pageIndex);
			window.parent.frames["ifrm_data"].refreshTree('${dept.deptId }','edit',alias,deptId,name);
			art.dialog.close();
		},1500);
	}
	function submitForm(pageIndex){
	 if($("#overDistrictName").val()==""){
			$("#overDistrictId").val("");
			 _tmpDwName="";
		}
		var name = $.trim($("#name").val());
		var alias = $.trim($("#alias").val());
		if($("#shortId").val()==""||$("#shortId").val().length!=2){
			art.dialog.tips("请输入2位的部门编码",1.5);
			return false;
		}
		if(name==""){
			art.dialog.tips("部门名称不能为空",1.5);
			return false;
		}
		if(alias==""){
			art.dialog.tips("部门简称不能为空",1.5);
			return false;
		}
		if (_tmpDwName != $("#overDistrictName").val()) {
			art.dialog.tips("输入驻外单位不存在！");
			$("#overDistrictName").focus();
			$("#overDistrictName").select();
			return false;
		}
		var deptId = $("#prefix").text()+$("#shortId").val()+$("#suffix").text();
		$("#alias").val(alias);
		$("#name").val(name);
		$("#longId").val(deptId);
				top.mask();
		$("#query_form").ajaxSubmit({
			type:"post",
			dataType:"json",
			success:function(data){
				top.unmask();
				switch(parseInt(data.success)){
					case 1:
						tipclose("机构编辑成功!",alias,deptId,name,pageIndex);
						break;
					case 2:
						art.dialog.tips("编辑失败，编号重复",1.5);
						break;
					case 3: 
						art.dialog.tips("编辑失败，名称或简称重复",1.5);
						break;
					default:
						art.dialog.tips("机构编辑失败！",1.5);
						break;
				}
			},
			error:function(){
				top.unmask();
				art.dialog.tips("机构编辑失败！",1.5);
			}
		});
	}
	$(function(){
		var deptId = '${dept.deptId }';
		var deep = '${dept.deep }';
		$("#prefix").text(deptId.substring(0,deep*2+2));
		$("#shortId").val(deptId.substring(deep*2+2,deep*2+4))
		$("#suffix").text(deptId.substring(deep*2+4));
		/**部门自动补全*/
		$("#overDistrictName").autocomplete("<c:url value='/dept/autocomplete.json'/>",{  
		  	minChars: 1,  
		  	max : 10, // 最大显示条数
		    autoFill: false,  
		    dataType : "json",  //指定数据类型的渲染方式  
		    extraParams:{  
		    	jpin:function(){  
			    	return $("#overDistrictName").val();//url的参数传递  
			    }
			},  
			parse: function(data){  
			    var rows = [];  
			    var d = data.depts;
			    if(d){
				    for(var i=0; i<d.length; i++){  
				    	rows[rows.length] = {  
					       	 data:d[i],  
					         value:d[i],  
					         result:d[i].name  
				        };  
				    }  
			    } 
			    return rows;  
			},  
			formatItem: function(row,i,n) {  
			    return row.name+"("+row.deptId+")";  
			}  
		  }).result (function(event, data, formatted) {  
		   	$("#overDistrictId").val(data.deptId);  
		   	_tmpDwName = data.name;
		  });
	})
	 var _tmpDwName = "${dept.overDistrictName}";//自动补全部门名称临时变量
</script>
</head>


<body >
<c:choose>
	<c:when test="${empty dept}">所选部门不可为空,请返回选择！</c:when>
	<c:otherwise>
			<form method="post" id="query_form" action="dept/saveedit.json" style="margin:0px;padding:0px;width:340px;">
				<table>
					<tr style="height:25px;">
						<td class="td_tit">上级部门:</td>
						<td>${dept.parentName }</td>
					</tr>
					<tr style="height:25px;">
						<td class="td_tit">部门名称:</td>
						<td><input type="text" size="35" style="width:230px;" onblur="this.value=this.value.replace(/\s/g,'');" id="name" maxlength="32" value="${dept.name}" name="name"></input><span style="color:red">*</span></td>
					</tr>
					<tr style="height:25px;">
						<td class="td_tit">部门编码:</td>
						<td><span id="prefix"></span><input size="2" style="width:18px" maxlength="2" id="shortId" onblur="this.value=this.value.replace(/\W/g,'')" type="text"></input><span id="suffix"></span><span style="color:red">*</span></td>
					</tr>
					<tr style="height:25px;">
						<td class="td_tit">部门简称:</td>
						<td><input type="text" size="35" style="width:230px;"  onblur="this.value=this.value.replace(/\s/g,'');" id="alias" maxlength="32" value="${dept.alias}" name="alias"></input><span style="color:red">*</span></td>
					</tr>
					<tr style="height:25px;">
						<td class="td_tit">部门简拼:</td>
						<td><input type="text" size="35" style="width:230px;"  onblur="this.value=this.value.replace(/\s/g,'');" id="jpin" maxlength="32" value="${dept.jpin }" name="jpin"></input><span style="color:red">*</span></td>
					</tr>
					<tr style="height:25px;">
						<td class="td_tit">人员总数:</td>
						<td><input type="text" size="35" style="width:230px;"  onblur="this.value=this.value.replace(/\s/g,'');" id="userTotal" maxlength="32" value="${dept.userTotal}" name="userTotal"></input></td>
					</tr>
					<tr style="height:25px;">
						<td class="td_tit">驻外部门:</td>
						<td><input type="text" size="35" style="width:230px;" onblur="this.value=this.value.replace(/\s/g,'');" id="overDistrictName" maxlength="32" value="${dept.overDistrictName}" name="overDistrictName"></input></td>
					    <input type="hidden" size="35" style="width:230px;"    id="overDistrictId" maxlength="32" value="${dept.overDistrictId}" name="overDistrictId"></input>
					</tr>
				</table>
				<input type="hidden" name="dbId" value="${dept.dbId }">
				<input type="hidden" name="deptId" id="longId"> 
				<input type="hidden" name="parentId" value="${parentId}"> 
			</form>
	</c:otherwise>
</c:choose>
</body>
</html>